package com.tuanzi.loan.web.bean.family;

import com.base.common.log.LogService;
import com.tuanzi.loan.business.entity.family.LoanWholeSaleComment;
import com.tuanzi.loan.business.service.family.LoanLargeAmountPlusRecordService;
import com.tuanzi.loan.vo.request.family.LoanLargeAmountPlusRecordSearchRequest;
import com.tuanzi.loan.vo.response.family.LoanLargeAmountPlusRecordSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.family.LoanLargeAmountPlusRecordDataModel;
import com.tuanzi.server.loan_base.util.DateUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
* @Description:    粤好外推用户明细后台
* @Author:         xionghao
* @CreateDate:      2018-09-04
*/
@Data
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanLargeAmountPlusRecordListBean
        extends JSFListingBean<LoanLargeAmountPlusRecordSearchRequest,LoanLargeAmountPlusRecordSearchResponse>{
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Autowired
    LoanLargeAmountPlusRecordService loanLargeAmountPlusRecordService;

    @PostConstruct
    private void init() {
        initLazyDataModel();
    }

    public void onReset() {
        initLazyDataModel();
    }

    public void onRefresh() {
        lazyDataModel = new LoanLargeAmountPlusRecordDataModel($);
        addSuccessfullyMessage();
    }

    private void initLazyDataModel() {
        $ = new LoanLargeAmountPlusRecordSearchRequest();
        try {
            $.setEndDate(DateUtils.formatYyyyMMddToDate(DateUtils.getCurrentDate()));
            $.setStartDate(DateUtils.formatYyyyMMddToDate(DateUtils.getTimeBeforeDays(1)));
        } catch (ParseException e) {
            LogService.error("日期转换异常",e);
        }
        lazyDataModel = new LoanLargeAmountPlusRecordDataModel($);
    }

    public String translate(String index){
        if ("1".equals(index)){
            return "上班族";
        } else if ("2".equals(index)) {
            return "个体户";
        }else if ("3".equals(index)){
            return "无固定职业";
        }else if("4".equals(index)){
            return "企业主";
        }else {
            return "未知";
        }
    }

    public List<String> getCfrom(){
        return loanLargeAmountPlusRecordService.getCfrom();
    }

    public List<LoanWholeSaleComment> getTypeOwnner(){
        return loanLargeAmountPlusRecordService.getTypeOwnner();
    }

    public List<String> getZhanNeiCFrom(){
        return loanLargeAmountPlusRecordService.getZhanNeiCFrom();
    }
}
